<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let person = {
        name: 'jack',
        hobbies: ['aaa', 'bbb', 'ccc']
    }

    function simpleCopy(obj) {
        if (!obj) return obj
        let result = {}
        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                result[key] = obj[key]
            }
        }
        return result
    }

    let k = simpleCopy(person)
    console.log(k)

    function deepCopy(obj) {


        let myObj = new obj.constructor()


        if (myObj === null) return obj

        if (myObj instanceof Date) return new Date(obj)

        if (myObj instanceof RegExp) return new RegExp(obj)

        if (typeof obj !== 'object') return obj

        for (let key in obj) {
            if (obj.hasOwnProperty(key)) {
                myObj[key] = deepCopy(obj[key])
            }
        }

        return myObj
    }


    let a = deepCopy(person)
    console.log(a)
    person.hobbies[0] = '2000'
    console.log(a)

</script>
</body>
</html>